package 力扣热题100;

import java.util.ArrayList;
import java.util.List;

public class LeetCode9 {
    List<String>list=new ArrayList<>();
    public List<String> letterCombinations(String digits) {
        char[][] arr = {{}, {},{'a', 'b', 'c'}, {'d', 'e', 'f'},
                {'g', 'h', 'i'}, {'j', 'k', 'l'}, {'m', 'n', 'o'},
                {'p', 'q', 'r', 's'}, {'t', 'u', 'v'}, {'w', 'x', 'y', 'z'}};
        int i=0;
        StringBuilder ret=new StringBuilder();
        find(arr,digits,i,ret);
        return list;
    }

    private void find(char[][] arr, String digits,int i,StringBuilder ret) {
        if(i==digits.length()){
            return;
        }
        int a=Integer.parseInt(digits.charAt(i)+"");//拿到第一个数字，并用来记录数组的行
        int k=0;//记录数组的列
        for (int j = 0; j < arr[a].length; j++) {
            ret.append(arr[a][k++]);//将第一个元素放入其中
            find(arr,digits,i+1,ret);
            if(ret.length()==digits.length()){
                list.add(ret.toString());
            }
            ret.deleteCharAt(ret.length()-1);//加完后出掉，因为要给下一个腾位置
        }
    }

    public static void main(String[] args) {
        LeetCode9 leetCode9=new LeetCode9();
        leetCode9.letterCombinations("23");
    }
}
